]> dgit.raspbian.org Git - gnome-shell.git/commitdiff
extensionUtils: Include arrays and objects in serialization
authorFlorian Müllner <fmuellner@gnome.org>
Thu, 20 Jun 2024 18:46:18 +0000 (20:46 +0200)
committerMarge Bot <marge-bot@gnome.org>
Wed, 16 Oct 2024 16:16:08 +0000 (16:16 +0000)
We currently only handle simple types when (de)serializing,
which means we miss keys like "shell-version" and "session-modes".

While there is no immediate use for those, handing arrays and
objects will allow to support the newly added "donate" metadata
in the Extensions app in the future.

https://gitlab.gnome.org/GNOME/gnome-shell/-/issues/6575

Part-of: <https://gitlab.gnome.org/GNOME/gnome-shell/-/merge_requests/3379>

js/misc/extensionUtils.js

index dc227801f8734337ed2bb3371bf8b64eb034b445..09338a182e4c1e8d23d30994691876ea6fc4a447 100644 (file)
@@ -36,6 +36,7 @@ const SERIALIZED_PROPERTIES = [
     'hasPrefs',
     'hasUpdate',
     'canChange',
+    'sessionModes',
 ];
 
 /**
@@ -52,9 +53,7 @@ export function serializeExtension(extension) {
         obj[prop] = extension[prop];
     });
 
-    let res = {};
-    for (let key in obj) {
-        let val = obj[key];
+    function packValue(val) {
         let type;
         switch (typeof val) {
         case 'string':
@@ -66,13 +65,28 @@ export function serializeExtension(extension) {
         case 'boolean':
             type = 'b';
             break;
+        case 'object':
+            if (Array.isArray(val)) {
+                type = 'av';
+                val = val.map(v => packValue(v));
+            } else {
+                type = 'a{sv}';
+                let res = {};
+                for (let key in val) {
+                    let packed = packValue(val[key]);
+                    if (packed)
+                        res[key] = packed;
+                }
+                val = res;
+            }
+            break;
         default:
-            continue;
+            return null;
         }
-        res[key] = GLib.Variant.new(type, val);
+        return GLib.Variant.new(type, val);
     }
 
-    return res;
+    return packValue(obj).deepUnpack();
 }
 
 /**
@@ -84,7 +98,7 @@ export function serializeExtension(extension) {
 export function deserializeExtension(variant) {
     let res = {metadata: {}};
     for (let prop in variant) {
-        let val = variant[prop].unpack();
+        let val = variant[prop].recursiveUnpack();
         if (SERIALIZED_PROPERTIES.includes(prop))
             res[prop] = val;
         else